package com.lc.cms.utils;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

@Getter
@Setter
@ToString
public class ResponseResult implements Serializable {

    private static final long serialVersionUID = 2808418446766431362L;

    /**
     * 是否成功，成功找data、失败找msg
     */
    private boolean success = false;

    /**
     * 返回结果编码，成功的话我喜欢设为0
     */
    private int code;

    /**
     * 返回消息，一般放置可追溯的错误消息
     */
    private String msg;

    /**
     * 返回数据
     */
    private Object data;

    private ResponseResult(boolean success, int code, String msg, Object data) {
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseResult success() {
        return new ResponseResult(true, 0, "", null);
    }

    public static ResponseResult success(Object data) {
        return new ResponseResult(true, 0, "", data);
    }

    public static ResponseResult error(int code, String msg) {
        return new ResponseResult(false, code, msg, null);
    }

    public static ResponseResult PARAMETER_ERROR = error(8001, "参数错误");
    public static ResponseResult UNKNOWN_ERROR = error(8101, "未知错误");
    public static ResponseResult OPERATION_FAILED = error(8201, "操作失败");
    public static ResponseResult DATA_NOT_AVAILABLE = error(8301, "数据不存在");
    public static ResponseResult SETTING_ALREADY_EXISTS = error(8401, "设置已存在");
}

